import { Column, IColumnProps } from "devextreme-react/data-grid";
import { ReactNode } from "react";
import { consts } from "./consts";
import { getAssertionTexts } from "./tableSamplingRecordService";

export const columnsDataMEJZ = [
    // PZID
    {
        dataField: "PZID",
        dataType: "string",
        caption: "组信息",
        width: 120,
        alignment: "center",
        groupIndex: 0,
    },
    {
        dataField: "ZY",
        caption: "摘要",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "KMBH",
        caption: "科目编号",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "KMMC",
        caption: "科目名称",
        alignment: "left",
    },
    {
        dataField: "JFJE",
        dataTypeCustom: "money-number",
        dataType: "number",
        caption: "借方",
        width: 150,
        editorOptions: {
            format: { type: 'decimal', currency: 'CNY', precision: 2 }
        },
        alignment: "right",
    },
    {
        dataField: "DFJE",
        dataTypeCustom: "money-number",
        dataType: "number",
        caption: "贷方",
        width: 150,
        editorOptions: {
            format: { type: 'decimal', currency: 'CNY', precision: 2 }
        },
        alignment: "right",
    },
    {
        dataField: "HSXM",
        caption: "核算项目",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "dfkmmc",
        caption: "对方科目",
        alignment: "left",
    },
    // {
    //     caption: "审定账龄",
    //     alignment: "center",
    //     columns: [
    //         // // 例如：1至3月M3(取M开头的+最后的月数)
    //     ]
    // }
];



export const conditionsColumnData = [{
    keyDataString: 'PZRQ',
    conditionsName: '凭证日期',
    sqlType: 'string'
}, {
    keyDataString: 'PZLX',
    conditionsName: '凭证类型',
    sqlType: 'string'
}, {
    keyDataString: 'PZBH',
    conditionsName: '凭证编号',
    sqlType: 'string'
}, {
    keyDataString: 'PZYF',
    conditionsName: '凭证月份',
}, {
    keyDataString: 'ZY',
    conditionsName: '摘要',
    sqlType: 'string'
}, {
    keyDataString: 'KMMC',
    conditionsName: '科目名称',
    sqlType: 'string'
}, {
    keyDataString: 'KMBH',
    conditionsName: '科目编号',
    sqlType: 'string'
}, {
    keyDataString: 'DFKMMC',
    conditionsName: '对方科目',
    sqlType: 'string'
}, {
    keyDataString: 'JFJE',
    conditionsName: '借方金额',
    sqlType: 'number'
}, {
    keyDataString: 'DFJE',
    conditionsName: '贷方金额',
    sqlType: 'number'
}, {
    keyDataString: 'FSE',
    conditionsName: '发生额',
    sqlType: 'number'
}, {
    keyDataString: 'HSXM',
    conditionsName: '核算项目',
    sqlType: 'string'
}];


export const conditionStatesData = [{
    StateID: 0,
    conditionName: '等于',
    slqfh: '='
}, {
    StateID: 1,
    conditionName: '不等于',
    slqfh: '<>'
}, {
    StateID: 2,
    conditionName: '大于',
    slqfh: '>'
}, {
    StateID: 3,
    conditionName: '大于且等于',
    slqfh: '>='
}, {
    StateID: 4,
    conditionName: '小于',
    slqfh: '<'
}, {
    StateID: 5,
    conditionName: '小于且等于',
    slqfh: '<='
}, {
    StateID: 6,
    conditionName: '区间',
    slqfh: 'between 0 and '
}, {
    StateID: 7,
    conditionName: '包含',
    slqfh: 'like'
}, {
    StateID: 8,
    conditionName: '不包含',
    slqfh: 'not like'
}, {
    StateID: 9,
    conditionName: '开头是',
    slqfh: 'like'
}, {
    StateID: 10,
    conditionName: '结尾是',
    slqfh: 'like'
}, {
    StateID: 11,
    conditionName: '空',
    slqfh: '='
}, {
    StateID: 12,
    conditionName: '不空',
    slqfh: '<>'
}, {
    StateID: 13,
    conditionName: '长度',
    slqfh: '='
}];



export const tempColumnsData = [
    // PZID
    {
        dataField: "PZID",
        dataType: "string",
        caption: "组信息",
        width: 120,
        alignment: "center",
        groupIndex: 0,
    },
    {
        dataField: "ZY",
        caption: "摘要",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "KMBH",
        caption: "科目编号",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "KMMC",
        caption: "科目名称",
        alignment: "left",
    },
    {
        dataField: "JFJE",
        dataTypeCustom: "money-number",
        dataType: "number",
        caption: "借方",
        width: 150,
        editorOptions: {
            format: { type: 'decimal', currency: 'CNY', precision: 2 }
        },
        alignment: "right",
    },
    {
        dataField: "DFJE",
        dataTypeCustom: "money-number",
        dataType: "number",
        caption: "贷方",
        width: 150,
        editorOptions: {
            format: { type: 'decimal', currency: 'CNY', precision: 2 }
        },
        alignment: "right",
    },
    {
        dataField: "HSXM",
        caption: "核算项目",
        width: 200,
        alignment: "left",
    },
    {
        dataField: "dfkmmc",
        caption: "对方科目",
        alignment: "left",
    },
    // {
    //     caption: "审定账龄",
    //     alignment: "center",
    //     columns: [
    //         // // 例如：1至3月M3(取M开头的+最后的月数)
    //     ]
    // }
];


export function getSamplingRecordColumns(props: {
    onEditClick?: (e: any) => void,
    onDelClick?: (e: any) => void,
    onTrackRecord?: (e: any) => void,//作为明细表追踪
}): IColumnProps[] {
    return [
        {
            dataField: 'rn',
            caption: consts.xh,
            alignment: 'center',
            width: 60,
            allowFiltering: false,

        },
        {
            dataField: 'samplePeriod',
            caption: '抽样期间',
            alignment: 'left',
            width: 120,
        },
        {
            dataField: 'sampleSource',
            caption: '样本来源',
            alignment: 'left',
            width: 120,
        },
        {
            dataField: 'itemName',
            caption: '抽样项目',
            alignment: 'left',
            minWidth: 120,
        }, {
            dataField: consts.sampledAllSampleSizeField,
            caption: '需测试全部数量',
            alignment: 'center',
            allowFiltering: false,
            width: 120,
        },
        {
            dataField: 'assertion',
            caption: '相关认定',
            alignment: 'left',
            width: 100,
            customizeText: (e: any) => {
                return getAssertionTexts((e.value || ''));
            },
        },
        {
            dataField: 'sampleMethodText',
            caption: '抽样方法',
            alignment: 'left',
            width: 150,
           /*  cellTemplate: (cellElement: HTMLElement, cellData: any) => {

                const sampleMethodActiveKey = cellData.data.sampleStepInfo?.sampleMethodActiveKey
                const title = consts.sampleMethodTabsTitle[sampleMethodActiveKey];
                cellElement.innerHTML = `${title}-${cellData.data.sampleMethod}`
            }, */
        },
     /*    {
            dataField: 'belongWorkPaper',
            caption: '归属底稿',
            alignment: 'left',
            width: 150,
        }, */ {
            dataField: 'createUser',
            caption: '操作人',
            alignment: 'left',
            width: 120,
        }, {
            dataField: 'createTime',
            caption: '操作时间',
            alignment: 'left',
            width: 140,
        }, {
            caption: '操作',
            type: 'buttons',
            fixed: true,
            width: props.onTrackRecord ? 40 : 80,
            fixedPosition: props.onTrackRecord ? 'left' : 'right',
            buttons: [
                {
                    icon: 'edit',
                    hint: '编辑',
                    visible: props.onEditClick != undefined,
                    onClick: (e: any) => {
                        props.onEditClick && props.onEditClick(e);
                    },
                },
                {
                    icon: 'trash',
                    hint: '删除',
                    visible: props.onDelClick != undefined,
                    onClick: (e: any) => {
                        props.onDelClick && props.onDelClick(e);
                    },
                },
                {
                    icon: 'info',
                    hint: '查看抽样参数',
                    text: '查看',
                    visible: props.onTrackRecord != undefined,
                    onClick: (e: any) => {
                        //console.log(e);
                        props.onTrackRecord && props.onTrackRecord(e);
                    },
                },
            ]
        }
    ]
}
/**
 * 抽样表表
 */
export function getSampleTableColumns(props: {
    onEditClick: (e: any) => void,
    onDelClick: (e: any) => void,
    tableTitleRender: (e: any) => ReactNode,
}): IColumnProps[] {
    return [
        {
            dataField: 'rn',
            caption: consts.xh,
            alignment: 'center',
            width: 60,
            allowFiltering: false,
            allowEditing: false,
        },
        {
            dataField: 'tableTitle',
            caption: '抽样表名',
            alignment: 'left',
            allowFiltering: true,
            allowEditing: true,
            cellRender: props.tableTitleRender
        },

    ]
}


export function getExcelTableColumns(): IColumnProps[] {
    return [
        /*   {
              dataField: 'rn',
              caption: consts.xh,
              alignment: 'center',
              width: 40,
              allowFiltering: false,
              allowEditing: false,
          }, */
        {
            dataField: 'tableTitle',
            caption: '表页名称',
            alignment: 'left',
            allowFiltering: true,
            allowEditing: false,
        },
        {
            dataField: 'tableName',
            caption: 'tableName',
            alignment: 'left',
            allowFiltering: true,
            allowEditing: false,
            visible: false, //需要隐藏起来,改名用到
        },
        {
            dataField: 'dataRowCount',
            caption: '数据行数',
            alignment: 'center',
            allowFiltering: true,
            allowEditing: false,
            width: 70,
        },
        /*  {
             dataField: 'totalCount',
             caption: '总行数',
             alignment: 'center',
             allowFiltering: true,
             allowEditing: false,
             width: 70,
         },
         {
             dataField: 'titleRowNo',
             caption: '标题行',
             alignment: 'center',
             allowFiltering: true,
             allowEditing: false,
             width: 70,
         },  {
             dataField: 'endRowNo',
             caption: '结束行',
             alignment: 'center',
             allowFiltering: true,
             allowEditing: false,
             width: 70,
         }, */


    ]
}
export const getNotExistsColumns = (tableTitle: string) => {
    return [
        {
            dataField: 'guid',
            caption: `【${tableTitle}】表没有列`,
            alignment: 'left',
            allowFiltering: false,
        }
    ]
}